<%@ page contentType="text/html; charset=UTF-8"%>
<%@include file="/html/portlet/chart/template/init.jsp"%>

<%
ChartTemplate template = null;
JSONArray templateParamArray = null;
long chartTemplateId = ParamUtil.getLong(request, "chartTemplateId");
if (chartTemplateId > 0) {
	template =ChartTemplateLocalServiceUtil.getChartTemplate(chartTemplateId);
	templateParamArray = JsonUtil.analysisTemplateParam(template.getTemplateParam());
}

%>

<div id="<portlet:namespace />template-script-param-fields">
	<aui:fieldset label="">
		<%
			if(templateParamArray!=null&&templateParamArray.length()>0){
				for (int i = 0; i < templateParamArray.length(); i++) {
					JSONObject templateParamObject=templateParamArray.getJSONObject(i);
		%>
		<div class="lfr-form-row lfr-form-row-inline">
			<div class="row-fields" style="display: flex;">
				<aui:input name='<%="paramtag"+(i+1) %>' value='<%=templateParamObject.getString("paramtag") %>' required="<%=true %>" label="chart.manage.template.script.param.tag" />
				<aui:input name='<%="paramname"+(i+1) %>' value='<%=templateParamObject.getString("paramname") %>' required="<%=true %>" label="chart.manage.template.script.param.name" />
				<aui:select name='<%="paramtype"+(i+1) %>' label="chart.manage.template.script.param.type" required="<%=true %>">
					<aui:option label="chart.manage.template.script.param.type.string" value="string" selected='<%="string".equals(templateParamObject.getString("paramtype")) %>'></aui:option>
					<aui:option label="chart.manage.template.script.param.type.number" value="number" selected='<%="number".equals(templateParamObject.getString("paramtype")) %>'></aui:option>
					<aui:option label="chart.manage.template.script.param.type.boolean" value="boolean" selected='<%="boolean".equals(templateParamObject.getString("paramtype")) %>'></aui:option>
				</aui:select> 
				<aui:input name='<%="paramhelp"+(i+1) %>' value='<%=templateParamObject.getString("paramhelp") %>' label="chart.manage.template.script.param.help" />
			</div>
		</div>
		<%			
				}
			}else{
		%>
		<div class="lfr-form-row lfr-form-row-inline">
			<div class="row-fields" style="display: flex;">
				<aui:input name='paramtag1' required="<%=true %>" label="chart.manage.template.script.param.tag" />
				<aui:input name='paramname1' required="<%=true %>" label="chart.manage.template.script.param.name" />
				<aui:select name='paramtype1' required="<%=true %>" label="chart.manage.template.script.param.type" >
					<aui:option label="chart.manage.template.script.param.type.string" value="string" ></aui:option>
					<aui:option label="chart.manage.template.script.param.type.number" value="number" ></aui:option>
					<aui:option label="chart.manage.template.script.param.type.boolean" value="boolean"></aui:option>
				</aui:select> 
				<aui:input name='paramhelp1' label="chart.manage.template.script.param.help" />
			</div>
		</div>

		<%		
			}
		%>
	</aui:fieldset>
</div>
<aui:script>
	AUI().use(
		'liferay-auto-fields',
		function(A) {
			new Liferay.AutoFields({
				contentBox : '#<portlet:namespace />template-script-param-fields > fieldset',
				fieldIndexes : '<portlet:namespace />template_script_param_fields_indexes'
			}).render();
		});
</aui:script>